package com.huifeng.utils;

import java.util.List;

public class PageUtils<T> {
    //书写方法

    public PageUtils(int totalCount, int pageSize, String currentPage) {
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        intcurrentPage(currentPage);
        intstartIndex();
        inttotalPage();
        intPrePage();
        intNextPage();
    }


    //初始化当前页码
    private void intcurrentPage(String currentPage) {
        if (currentPage == null || currentPage.equals("")) {
            this.currentPage = 1;
        } else {
            this.currentPage = Integer.parseInt(currentPage);
        }
    }

    //初始化起始下标
    private void intstartIndex() {
        this.startIndex = (this.currentPage - 1) * this.pageSize;
    }

    //初始化总页数
    private void inttotalPage() {
        this.totalPage = this.totalCount % this.pageSize == 0 ?
                this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
    }

    //初始化上一页
    private void intPrePage() {
        //添加判断
        if (this.currentPage == 1) {
            this.prePage = 1;
        } else {
            this.prePage = this.currentPage - 1;
        }

    }

    //初始化下一页
    private void intNextPage() {
        if (this.currentPage == this.totalPage) {
            this.nextPage = this.totalPage;
        } else {
            this.nextPage = this.currentPage + 1;
        }
    }

    private int totalCount;//总记录数
    private int pageSize;//页容量
    private int currentPage;//当前页码

    private int startIndex;//每一条记录的起始下标
    private int totalPage; //总页数
    private int prePage; //上一页
    private int nextPage;  //下一页

    private List<T> list;

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPrePage() {
        return prePage;
    }

    public void setPrePage(int prePage) {
        this.prePage = prePage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
